home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / asm32.zip / E32.ZIP / INSKEY.ASM < prev    next >
Assembly Source File  |  1994-12-29  |  2KB  |  103 lines

  1. ; INSKEY.ASM for E32 - Copyright (C) 1994 Douglas Herr
  2. ;  all rights reserved
  3.  
  4. ;
  5. ; This routine adds a character to the file.  In insert mode, remaining
  6. ; characters are pushed forward.  If a CR is inserted, LF is also added.
  7. ;
  8.  
  9. include    model.inc
  10.  
  11. public    insert_key, advance
  12. extrn    right:near
  13. extrn    open_space:near
  14. extrn    save_char:near
  15. extrn    display_bottom:near
  16. extrn    home:near
  17. extrn    down:near
  18.  
  19. CR    equ    0Dh
  20. LF    equ    0Ah
  21. TAB    equ    09h
  22.  
  23. include    dataseg.inc
  24. extrn    cursor:dword, dirty_bits:byte
  25. extrn    insert_mode:byte, undo_length:dword
  26. extrn    display_mode:byte
  27. @curseg    ends
  28.  
  29. include    codeseg.inc
  30. insert_key    proc    near
  31.     push    es
  32.     push    fs
  33.     pop    es
  34.     assume    es:nothing
  35.     mov    esi,cursor
  36.  
  37. ;
  38. ; check for HEX display mode
  39. ; and skip insert stuff if so
  40. ;
  41.     cmp    display_mode,4
  42.     je    short not_tab
  43.  
  44. ;
  45. ; ASCII display mode
  46. ;
  47.     cmp    al,CR            ; is the char a CR?
  48.     je    short new_line
  49.     cmp    insert_mode,0        ; insert mode?
  50.     jne    short insert_char
  51.     cmp    byte ptr es:[esi],CR    ; at end of line?
  52.     je    short insert_char
  53.     cmp    al,tab            ; new char a TAB?
  54.     jne    short not_tab            ; no special handling if not
  55.     cmp    es:[esi],al        ; at a TAB?
  56.     jne    short insert_char    ; insert tab if old char <> TAB
  57. not_tab:
  58.     mov    edi,esi
  59.     xchg    es:[esi],al        ; swap new char for old
  60.     call    save_char        ; store the old one
  61.     jmp    short adv0
  62. insert_char:
  63.     push    eax        ; save the new character
  64.     mov    eax,1
  65.     call    open_space    ; ret: ESI = cursor
  66.     pop    eax
  67.     mov    edi,esi
  68.     jc    short file_full    ; CF if file full
  69.     stosb
  70. adv0:
  71.     or    dirty_bits,4    ; current line is dirty
  72.     push    undo_length
  73.     call    right        ; move cursor to next letter
  74.     pop    undo_length
  75.     or    dirty_bits,11000000b
  76. file_full:
  77.     clc
  78.     pop    es
  79.     ret
  80.  
  81. advance:
  82.     push    es
  83.     jmp    adv0
  84.  
  85. new_line:
  86.     push    esi
  87.     mov    eax,2
  88.     call    open_space    ; make room for CR+LF
  89.     pop    edi
  90.     jc    file_full
  91.     mov    ax,LF*256+CR
  92.     stosw
  93.     call    display_bottom
  94.     call    home
  95.     call    down
  96.     or    dirty_bits,11000001b
  97.     pop    es
  98.     ret
  99. insert_key    endp
  100.  
  101. @curseg    ends
  102.     end
  103.